package listdemo;

import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;

class Employee{

    private String name;
    private String gender;
    private int age;

    public Employee(String name, String gender, int age) {
        this.name = name;
        this.gender = gender;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Employee{" +
                "name='" + name + '\'' +
                ", gender='" + gender + '\'' +
                ", age=" + age +
                '}';
    }
}
public class ListOperateDemo {

    public static void main(String[] args) {
        List list = new LinkedList();
        Employee e1 = new Employee("张三","男",20);
        Employee e2 = new Employee("李四","女",18);
        Employee e3 = new Employee("王五","男",20);
        Employee e4 = new Employee("赵六","女",22);

        System.out.println("----------添加元素-----------");
        list.add(e1);
        list.add(e2);
        list.add(e3);
        list.add(e1);
        list.add(e4);

        System.out.println("序列长度是："+list.size());

        for(Object obj : list){
            System.out.println(obj);
        }
        System.out.println("----------指定位置插入新元素-----------");
        list.add(1,new Employee("王大锤","男",19));

        for(Object obj : list){
            System.out.println(obj);
        }

        System.out.println("----------获取子集合--------");
        List subList =  list.subList(1,list.size());
        for(Object obj : subList){
            System.out.println(obj);
        }

        System.out.println("-------------删除元素------------");

        list.remove(e1); //删除张三对象，仅仅删除掉第一个张三对象
        //list.removeAll(Arrays.asList(new Students[]{s1})); //删除所有的张三对象

        for(Object obj : list){
            System.out.println(obj);
        }

        System.out.println(list.contains(e4));

        System.out.println(Arrays.toString(list.toArray()));
        System.out.println(list.isEmpty());

        list.clear();
        System.out.println(list.isEmpty());
    }
}
